
import React, { Suspense } from 'react'
import { Navigate, useRoutes } from 'react-router-dom'
import Redirect from './Redirect'

// const getApiRouter = () => {
//   return new Promise((resolve, reject) => {
//     const routeList = ['/home', '/list1']
//    try {
//      setTimeout(() => {
//       resolve(routeList)
//     }, 1000)
//    } catch (error) {
//     reject(error)
//    }
//   })
// }

export const routeConfig = [
  { path: '/', element: <Redirect to="/home" /> },
  {
    path: '/home',
    element: lazyLoad('home')
  },
  {
    // path: '/about',
    element: lazyLoad('about'),
    children: [
      // { path: '', element: <Navigate to="/about/aboutDetail" /> },
      { path: 'aboutDetail', element: lazyLoad('about/detail') }
    ]
  },
  { path: '*', element: lazyLoad('NotFound') }
]

// 路由懒加载，拆分项目js体积
function lazyLoad(path) {
  const Component = React.lazy(() => import(`../views/${path}`))
  return (
    <Suspense loading={<div>loading中...</div>}>
      <Component />
    </Suspense>
  )
}
